package com.edu.contorller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

@Controller
public class HeaderTest {


//    @RequestMapping("/headerTest")
//    public String headerTest(HttpServletRequest request){
//        //使用request对象去获取请求头中的数据
//        System.out.println(request.getHeader("User-Agent"));
//        return "index.jsp";
//    }

    @RequestMapping("/headerTest")
    public String headerTest(@RequestHeader("User-Agent") String userAgent,@RequestHeader(value="Referer",required = false) String referer){
        System.out.println("浏览器信息:"+userAgent);
        System.out.println("请求来源页面"+referer);
        return "index.jsp";
    }

}
